home *** CD-ROM | disk | FTP | other *** search
- Path: news.dx.net!news
- From: erowe@bayou.com
- Newsgroups: comp.lang.c++
- Subject: Reading File with Structure Problem
- Date: Sun, 21 Jan 96 03:01:14 GMT
- Organization: The DataXchange Network, Inc
- Message-ID: <N.012096.210114.91@mail>
- NNTP-Posting-Host: 199.190.112.30
- X-Newsreader: Quarterdeck Message Center [1.0]
-
- I am having difficulty reading in a file into a structure. The file's contents
- is "123456789John Doe", but try as I may I cannot get "123456789" into the ssn
- variable, nor can I get "John Doe" into the name variable. 8-( Any insights
- greatly appreciated...below is my source:
-
- #include <iostream.h>
- #include <fstream.h>
-
- void main(void)
- {
-
- struct gradebook {
- char ssn[10];
- char name[10];
- } student;
-
- ifstream student_file("test.dat");
-
- student_file.read((char *) &student, sizeof(gradebook));
-
- cout << "SSN" << student.ssn << endl;
- cout << "Name" << student.name << endl;
- }
-
- //test.dat is a file that contains the following (w/o a return character)
- //123456789john doe
-
-
-
-
-
-